Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pull up c-band prefix decoding #174

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

rpatel3001
Copy link
Contributor

@rpatel3001 rpatel3001 commented Oct 28, 2024

doing it this way means using top level MessageDecoder instance in all the tests instead of an instance of the specific plugin being tested. if that's ok i can update the rest to match (and check if the C-Band prefix test matches any messages it shouldn't).

Summary by CodeRabbit

  • New Features

    • Enhanced the message decoding process to recognize specific header formats containing flight and message numbers, ensuring complete and accurate output.
  • Refactor

    • Streamlined the decoding logic across various message types to improve consistency and reliability in the formatted results.


// https://app.airframes.io/messages/3452310240
const text = '101606,1910,.N317FR,,KMDW,----,1,1016,RT0,LT1,';
const decodeResult = decoderPlugin.decode({ text: text });
const decodeResult = decoder.decode({ label: "4A", text: text });
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this isn't a bad idea, but it's going to make the PR huge. Do we want a separate PR that just makes this change? Or do we want to move the c-band messages to the MessageDecoder suite? I'm leaning towards moving the c-band tests

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving the c band message tests makes sense with two drawbacks:

  1. Need to remember to add tests in a second location for types with this prefix
  2. More importantly, there's no way to check if the cband prefix accidentally catches non cband messages and incorrectly truncates the message that it passes into a plugin.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we have messages (minus the prefix) that are unique to c-band? If not, i don't think we need to have c-band label-specific tests other than a couple to test the prefix extraction.

As for the second point, idk. Is it worth slowing down the test suite by making every test run through the plugin selection code just so we can verify this edge case that we don't even know exists?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure about any cband specific messages, but the regex for the prefix is pretty permissive. i would be surprised if it never matched any non cband messages. maybe it would be better to send more metadata about the source of the message into the decoders and just tell it explicitly if it's cband?

or we could try to decode as cband if the prefix is detected then retry with the prefix still attached if it fails to decode. that wouldn't necessarily catch every edge case though

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kevinelliott and @andermatt64 - Do you have any opinions here?

@rpatel3001 rpatel3001 force-pushed the cband_prefix branch 2 times, most recently from 84e959e to cf15587 Compare October 30, 2024 23:21
@makrsmark makrsmark force-pushed the master branch 3 times, most recently from 3447c21 to 1e877a4 Compare November 20, 2024 11:03
@rpatel3001 rpatel3001 force-pushed the cband_prefix branch 2 times, most recently from ad6e34a to da1033b Compare November 24, 2024 04:25
@kevinelliott
Copy link
Contributor

@rpatel3001 @andermatt64 @makrsmark Any further thoughts here? It would be good to get this one finished up.

@andermatt64
Copy link
Contributor

@rpatel3001 @andermatt64 @makrsmark Any further thoughts here? It would be good to get this one finished up.

I think I'm ok with the airline+number regex if historical C-band messages can be consistently caught with it.

@rpatel3001
Copy link
Contributor Author

last thing to resolve is the conversation about how to do c-band tests: make each plugin test use decoder instead of decoderPlugin or do a handful of c-band tests as part of the MessageDecoder test suite.

@kevinelliott
Copy link
Contributor

@coderabbitai full review

Copy link

coderabbitai bot commented Mar 10, 2025

✅ Actions performed

Full review triggered.

Copy link

coderabbitai bot commented Mar 10, 2025

Walkthrough

This pull request enhances the message decoding process by updating the MessageDecoder.decode method to recognize a 10-character header containing a message number and flight number via a regular expression. When a header is detected, the method extracts the components and calls ResultFormatter.flightNumber while adjusting the message text accordingly. Additionally, several plugin files and their associated tests (Labels 30, 4A, 4N, and 83) have been refactored to directly use the MessageDecoder instance instead of individual plugin instances. A minor formatting change was also made to Label_1L_Slash.ts.

Changes

File(s) Change Summary
lib/MessageDecoder.ts Adds regex-based header parsing in decode to extract message and flight numbers; calls ResultFormatter.flightNumber and adjusts text processing.
lib/plugins/Label_1L_Slash.ts Inserts a newline character before the export default {}; statement; no change in functionality.
lib/plugins/Label_30_Slash_EA.test.ts Updates the test to replace decoderPlugin.decode({ text }) with decoder.decode({ label: "30", text }), modifying the parameters passed to the decoding function.
lib/plugins/Label_4A/4N/83 (.ts & .test.ts) Refactors plugin classes and tests to remove intermediate text variables by directly using message.text and invoking MessageDecoder.decode({ label, text }); updates expected output assertions.

Sequence Diagram(s)

Loading
sequenceDiagram
  participant C as Caller
  participant MD as MessageDecoder
  participant RX as Regex Parser
  participant RF as ResultFormatter

  C->>MD: decode(message)
  MD->>RX: Check for 10-character header
  alt Header Matched
    RX-->>MD: Return extracted groups (message number, flight number)
    MD->>RF: flightNumber(airlineCode, flightNumber)
    MD->>MD: Adjust text with header restored
  else No Header
    RX-->>MD: No match found
    MD->>MD: Process message normally
  end
  MD-->>C: Return decoded message

Possibly related PRs

Poem

I'm a bunny hopping through the code all day,
Nibbling on regex carrots along the way.
Headers and flights now dance in the light,
With every change, my heart feels light.
In fields of tests and refactored delight,
I celebrate these changes with a joyful bite! 🐰✨

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Sorry, something went wrong.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6c20459 and fe1cdc7.

📒 Files selected for processing (9)
  • lib/MessageDecoder.ts (3 hunks)
  • lib/plugins/Label_1L_Slash.ts (1 hunks)
  • lib/plugins/Label_30_Slash_EA.test.ts (1 hunks)
  • lib/plugins/Label_4A.test.ts (6 hunks)
  • lib/plugins/Label_4A.ts (2 hunks)
  • lib/plugins/Label_4N.test.ts (5 hunks)
  • lib/plugins/Label_4N.ts (2 hunks)
  • lib/plugins/Label_83.test.ts (6 hunks)
  • lib/plugins/Label_83.ts (2 hunks)
🔇 Additional comments (20)
lib/plugins/Label_1L_Slash.ts (1)

83-83: Good formatting change.

Adding a newline at the end of the file is a good practice that helps meet common coding standards and avoids "No newline at end of file" warnings from linters.

lib/plugins/Label_4A.ts (2)

24-24: Improved code by removing intermediate variable.

Directly using message.text.split(",") instead of an intermediate variable simplifies the code and aligns with how the other decoders have been refactored.


62-62: Consistent use of message.text.

Using message.text directly in the error case maintains consistency with other changes and the decoder pattern being implemented throughout the codebase.

lib/MessageDecoder.ts (3)

5-5: Required import added for the new functionality.

The ResultFormatter import is necessary for the new C-Band prefix handling that uses ResultFormatter.flightNumber().


99-105: Well-implemented C-Band prefix detection and extraction.

The implementation follows a clear pattern:

  1. Identify messages with a 10-character C-Band header using a descriptive regex
  2. Extract the message number, airline code, and flight number
  3. Temporarily remove the prefix from the message text for downstream processing

The regex pattern ^(?<msgno>[A-Z]\d{2}[A-Z])(?<airline>[A-Z0-9]{2})(?<number>[0-9]{4}) captures the structure documented in previous discussions about C-Band prefixes.


162-165: Good restoration and enrichment of message data.

After processing the message with plugins, the implementation:

  1. Properly checks if a C-Band prefix was detected
  2. Adds the flight number information using ResultFormatter.flightNumber()
  3. Restores the original message text with the prefix

This approach preserves the original message while enriching the decoded result with flight information.

lib/plugins/Label_30_Slash_EA.test.ts (1)

17-17: Test updated to use MessageDecoder instead of plugin instance directly.

This change aligns with the PR objective of using a top-level MessageDecoder instance across all tests. The test now passes both the label and text to the decoder, which better matches the actual usage pattern in the application.

lib/plugins/Label_4N.test.ts (3)

17-17: Refactoring to use MessageDecoder directly

This change aligns with the PR objective of using a top-level MessageDecoder instance for tests instead of individual plugin instances. This approach is more consistent with how the decoder would be used in production.


42-42: Consistent use of MessageDecoder across all test cases

All test cases have been updated to use the MessageDecoder instance directly, providing a consistent testing approach throughout the file.

Also applies to: 75-75, 102-102, 133-133


113-126: Updated expectations for C-band message format

The order of the formatted items has been adjusted, with the flight number now appearing as the last item in the array. This change reflects the new structure where the MessageDecoder handles C-band prefix decoding rather than the individual plugin.

lib/plugins/Label_83.ts (1)

23-23: Direct use of message.text instead of intermediate variable

The code now directly references message.text instead of using a local variable. This simplification is cleaner and reduces unnecessary variable assignments, which is a positive change that helps maintain consistency across plugins.

Also applies to: 25-26, 35-35, 37-38, 42-43

lib/plugins/Label_4N.ts (1)

22-31: Simplified message text handling

Similar to the changes in Label_83.ts, this plugin now directly uses message.text instead of an intermediate variable. This simplification makes the code more straightforward and aligns with the architectural change to move C-band prefix handling to the MessageDecoder.

Also applies to: 49-49

lib/plugins/Label_83.test.ts (2)

17-17: Consistent testing methodology using MessageDecoder

All test cases now use the MessageDecoder instance directly for decoding, passing both the label and text. This approach is more consistent with real-world usage and aligns with the PR objective.

Also applies to: 53-53, 92-92, 121-121, 145-145, 171-171


71-85: Updated item order in formatted results for C-band messages

The expectations for C-band message test cases have been updated to reflect the new structure where flight number appears as a separate item. This is consistent with the changes in Label_4N.test.ts and reflects the architectural change where the MessageDecoder handles C-band prefix decoding.

Also applies to: 159-165

lib/plugins/Label_4A.test.ts (6)

21-21: Methodology update aligns with PR objectives

This change moves from direct plugin invocation to using the top-level MessageDecoder, aligning with the PR's goal of centralizing the C-band prefix decoding.


47-47: Centralized decoder approach matches PR objectives

Switching to the top-level decoder instance is consistent with the discussions in previous reviews about improving the C-band prefix handling.


55-55: Ensure item count reduction is intentional

Similar to line 29, the expected item count has been reduced from 5 to 4. This appears to be related to how the MessageDecoder now processes these messages.


71-71: Consistent methodology across all test cases

The change to use the top-level decoder is applied consistently across all test variants, which is good for maintainability and aligns with the PR objectives.

Also applies to: 95-95, 121-121


29-29:

✅ Verification successful

Verify the expected item count reduction

The expected length of formatted items has been reduced from 6 to 5. This change appears to be related to how the message is now being processed by the central decoder.


🏁 Script executed:

#!/bin/bash
# Check if any similar tests were modified to reduce expected item counts
grep -n "expect.*formatted.items.length" lib/plugins/*.test.ts | grep -B 1 -A 1 "toBe"

Length of output: 16474


Central Decoder Update: Expected Item Count Reduction Confirmed

The change in expected item count—from 6 to 5—in lib/plugins/Label_4A.test.ts (line 29) is consistent with the updates observed across similar tests in the repository. The grep results confirm that the new expected value (5) reflects the revised central decoder processing logic. No additional changes are needed here.


104-114:

✅ Verification successful

C-Band flight information now appears at the end

The order of formatted items in the C-Band test case has changed, with the 'FLIGHT' item now placed at the end of the array. This likely reflects how the central decoder now processes C-Band messages with flight information.


🏁 Script executed:

#!/bin/bash
# Check how the MessageDecoder is handling flight information for C-Band messages
cat lib/MessageDecoder.ts | grep -A 30 "decode" | grep -A 30 "flight"

Length of output: 1814


Flight Information Order Change Validated

The updated test snapshot in lib/plugins/Label_4A.test.ts now correctly expects the flight information (FLIGHT) to appear as the last item in the formatted items array. Verification via the MessageDecoder.ts snippet confirms that the flight number is appended—via the ResultFormatter.flightNumber call—after processing the other fields, which aligns with the expected behavior.

No further modifications are required.

Comment on lines +147 to +151
// expect(decodeResult.decoded).toBe(false);
// expect(decodeResult.decoder.decodeLevel).toBe('none');
expect(decodeResult.decoder.name).not.toBe('label-4a');
// expect(decodeResult.formatted.description).toBe('Latest New Format');
// expect(decodeResult.formatted.items.length).toBe(0);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Update or restore the commented assertions

Several assertions have been commented out rather than updated. To ensure complete test coverage, consider either:

  1. Updating these assertions to match the new expected behavior, or
  2. Adding new assertions that verify the correct behavior under the new decoding approach

The current approach may leave some aspects of the invalid case handling untested.

-//  expect(decodeResult.decoded).toBe(false);
-//  expect(decodeResult.decoder.decodeLevel).toBe('none');
+  expect(decodeResult.decoded).toBe(false);
+  // If decoding behavior has changed, update expected values:
+  expect(decodeResult.decoder.decodeLevel).toBe('none');
   expect(decodeResult.decoder.name).not.toBe('label-4a');
-//  expect(decodeResult.formatted.description).toBe('Latest New Format');
-//  expect(decodeResult.formatted.items.length).toBe(0);
+  // Add appropriate assertions for the new decoding approach
+  expect(decodeResult.formatted.items.length).toBe(0);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// expect(decodeResult.decoded).toBe(false);
// expect(decodeResult.decoder.decodeLevel).toBe('none');
expect(decodeResult.decoder.name).not.toBe('label-4a');
// expect(decodeResult.formatted.description).toBe('Latest New Format');
// expect(decodeResult.formatted.items.length).toBe(0);
expect(decodeResult.decoded).toBe(false);
// If decoding behavior has changed, update expected values:
expect(decodeResult.decoder.decodeLevel).toBe('none');
expect(decodeResult.decoder.name).not.toBe('label-4a');
// Add appropriate assertions for the new decoding approach
expect(decodeResult.formatted.items.length).toBe(0);

@rpatel3001
Copy link
Contributor Author

revisiting this, I think I agree that adding c-band tests to each message type is perhaps too much and so it would be better to have a c-band specific test file. i can pull them out and revert the existing tests in the next couple days

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants